package com.company.笔试.连续子数组和;

import java.util.*;

public class Solution {
    public static int FindGreatestSumOfSubArray(int[] array) {
        int len = array.length;
        if(len<=0) return 0;
        if(len==1) return array[0];
        int[] dp = new int[len];
        dp[0] = array[0];
        int res= Integer.MIN_VALUE;
        for (int i = 1; i < len; i++) {
            dp[i] = Math.max(array[i],array[i]+dp[i-1]);
            if (dp[i]>res) res =dp[i];
        }
        for (int i : dp) {
            System.out.println(i);

        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(Solution.FindGreatestSumOfSubArray(new int[]{1, -2, 3, 10, -4, 7, 2, -5}));
    }
}